<?php
/**
 * @Author: nic-tes
 * @Date:   2014-09-05 16:34:16
 * @Last Modified by:   nic-tes
 * @Last Modified time: 2014-09-05 16:37:33
 */
class LoginControl extends Control{
	/**
	 * [index 登陆控制器]
	 * @return [type] [description]
	 */
	public function index(){
		// 判断是不是post提交
		if (IS_POST) {
			$code=strtoupper($_POST['verify']);
			// 判断验证码是否错误
			if (!$_SESSION['code']==$code)$this->error('验证码错误');
			$user=$_POST['userName'];
			$password=md5($_POST['psd']);
			$result=M('admin')->where('username='.'"'.$user.'"'.' and '.'passwd='.'"'.$password.'"')->find();
			if ($result['username']==$user&&$result['passwd']==$password) {
				if($result['lock']==1)$this->error('用户被锁定，暂时无法登陆');
				$_SESSION['aid'] = $result['aid'];
				$_SESSION['adminname'] =$result['username'];

			$data = array(
			'logintime' => time(),
			'loginip' 	=>$_SERVER['REMOTE_ADDR'],
					);
			$re=M('admin')->where('aid='.$result['aid'])->update($data);

				if(isset($re)){
					$this->success('登录成功',__ROOT__);
				}else{
					$this->success('登录成功,但是有错误',__ROOT__);
				}

			}else{
				$this->error('账号或密码错误');
			}
		}
	$this->display();
	}
	public function out(){
		unset($_SESSION['aid']);
		unset($_SESSION['adminname']);
		$this->success('退出成功',__ROOT__);
	}





		
	
	public function code(){
		$code=new code();
		$code->show();
	}


	
}
?>